<?php
/**
 * @package orinoco.framework
 * @subpackage request
 * @author Ryan Yonzon <rawswift@gmail.com>
 * @copyright Copyright 2008-2009 Ryan Yonzon 
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
 */

/**
 * object representation of $_POST and $_GET request/method
 */
class dataObject {

	private $_value = NULL;
	
	/**
	 * return value if object is used as string
	 *
	 * @return string current value
	 */
	public function __toString() {
		return isset($this->_value) ? $this->_value : '';		
	}

	/**
	 * set object value
	 *
	 * @param mixed $_v value
	 */
	public function set_value($_v) {
		$this->_value = $_v;
	}

	/**
	 * returns objects value
	 *
	 * @return mixed current value
	 */
	public function get_value() {
		return $this->_value;
	}
	
	/**
	 * convert to uppercase
	 *
	 * @return string uppercased
	 */
	public function to_upper() {
		return strtoupper($this->_value);
	}

	/**
	 * convert to lowercase
	 *
	 * @return string lowercased
	 */
	public function to_lower() {
		return strtolower($this->_value);
	}

	/**
	 * uppercase first char of string
	 *
	 * @return string uppercased first char
	 */
	public function to_upper_first() {
		return ucfirst($this->_value);
	}
	
	/**
	 * uppercase first char of words
	 *
	 * @return string uppercased first char of every words on string
	 */
	public function to_upper_words() {
		return ucwords($this->_value);
	}
	
	/**
	 * convert object value to a permalink format 
	 *
	 * @return string permalink format
	 */
	public function to_permalink() {
		$_patterns = array('(-)', '(\')', '( )');
		$_replacements = array(';', '+', '-');
		return preg_replace($_patterns, $_replacements, $this->_value);
	}
	
	/**
	 * returns MD5 hash with salt option
	 *
	 * @param string $_salt salt
	 * @return MD5 hash
	 */
	public function md5_hash($_salt = NULL) {
		return md5($this->_value . $_salt);
	}

	/**
	 * returns SHA-1 hash with salt option
	 *
	 * @param string $_salt salt
	 * @return SHA-1 hash
	 */
	public function sha1_hash($_salt = NULL) {
		return sha1($this->_value . $_salt);
	}
	
} // end class

// -EOF-